package com.aegean.CommercialHotelBookSystem.user.action;

import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import com.aegean.CommercialHotelBookSystem.factory.BusinessFactory;
import com.aegean.CommercialHotelBookSystem.factory.MyTools;
import com.aegean.CommercialHotelBookSystem.factory.MyTools.*;
import com.aegean.CommercialHotelBookSystem.model.Customer;
import com.aegean.CommercialHotelBookSystem.user.business.IUserBusiness;
import com.aegean.CommercialHotelBookSystem.user.dao.Impl.UserDaoImpl;

public class LoginUser extends HttpServlet {
	protected void doGet(HttpServletRequest request,
			HttpServletResponse response) throws ServletException, IOException {
		doPost(request, response);
	}

	protected void doPost(HttpServletRequest request,
			HttpServletResponse response) throws ServletException, IOException {
		String User_Login = MyTools.toChinese(request
				.getParameter("User_Login"));
		String User_Pwd = MyTools.toChinese(request.getParameter("User_Pwd"));
		if (User_Login == null || User_Pwd == null || User_Login.equals("")
				|| User_Pwd.equals("")) {
			request.getRequestDispatcher("/User/User_login.jsp").forward(
					request, response);
		} else {
			IUserBusiness business = BusinessFactory.createUserBusiness();
			Customer one = business.loginUser(User_Login, User_Pwd);
			if (one == null) {
				request.getRequestDispatcher("/User/User_login.jsp").forward(
						request, response);
			} else {
				HttpSession session = request.getSession();
				session.setAttribute("Login_User", one);
				request.getRequestDispatcher("/User/User_index.jsp").forward(
						request, response);
			}
		}
	}

}
